package STUDENT.LETRUNGHIEU.GENERICS_EXERCISES.models;

import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;

import STUDENT.LETRUNGHIEU.GENERICS_EXERCISES.objects.Book;
import STUDENT.LETRUNGHIEU.GENERICS_EXERCISES.objects.BookStore;
import STUDENT.LETRUNGHIEU.GENERICS_EXERCISES.objects.Reader;

public class Models {
	BookStore storeObj = new BookStore();
	
	public void addBook(Book bookObj){
		storeObj.getBookList().add(bookObj);
	}
	
	public void showBook(){
		Iterator<Book> itr = storeObj.getBookList().iterator();
		
		while(itr.hasNext()){
			Book bookObj = (Book) itr.next();
			System.out.println(bookObj);
		}
	}
	
	public void addReader(Reader readerObj){
		storeObj.getReaderList().add(readerObj);
	}
	
	public void showReader(){
		Iterator<Reader> itr = storeObj.getReaderList().iterator();
		
		while(itr.hasNext()){
			Reader readerObj = (Reader) itr.next();
			System.out.println(readerObj);
		}
	}
	
	public void brrowBook(String bookName, String readerName){
		Iterator<Book>   itr  = storeObj.getBookList().iterator();
		Iterator<Reader> itr2 = storeObj.getReaderList().iterator();
		
		String bookNameBr = null, readerNameBr = null;
		
		while(itr.hasNext()){
			if(bookName.equals(itr.next().getBookName()))
				bookNameBr = bookName;
		}
		while(itr2.hasNext()){
			if(readerName.equals(itr2.next().getReaderName()))
				readerNameBr = readerName;
		}

		storeObj.getMap().put(bookNameBr, readerNameBr);
	}
	
	public void showBorrow(){
		Set<Entry<String, String>> entries = storeObj.getMap().entrySet();
		
		for (Entry<String, String> entry : entries) {
            System.out.println("Book: " + entry.getKey() + " - Reader: " + entry.getValue());
        }
		
	}

}
